home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1157.ASC < prev    next >
Text File  |  1992-11-11  |  4KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                                    NUMBER  :  1157
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  November 11, 1992                                 PAGE  :  1/3
  12.  
  13.     TITLE  :  Determining Extended Memory Size from CMOS.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.   /* -------------------[  ACCESSING CMOS DATA ]------------------------ *\
  20.  
  21.   The AT CMOS RAM can be accessed through ports 70H ( Control/Address )
  22.   and 71h( CMOS Data ).   When reading CMOS RAM, one must:
  23.  
  24.       1.  Disable interrupts.
  25.           ( This ensures that no interruption takes place between
  26.             items 2. and 4. listed below ).
  27.  
  28.       2.  Write the offset of the CMOS RAM data to be fetched to I/O
  29.           port 70h.
  30.  
  31.       3.  Given the increasing speed of CPUs, it may be necessary to
  32.           create a delay between items 2. and 4.   The simplest way to
  33.           achieve the delay is via a 'jmp' instruction:
  34.  
  35.                           asm jmp short $+2
  36.  
  37.           Include the '#pragma inline' directive in the source code when
  38.           using the above so that the assembler ( TASM by default ) may
  39.           process the 'jmp'.   Alternatively a 'goto/Label:' combination
  40.           or an '__emit__()' statement may also be used.
  41.  
  42.       4.  Read the Data ( a byte ) from port 71h.
  43.       5.  ReEnable Interrupts.
  44.  
  45.   Writing to CMOS RAM is similar to the process above:
  46.  
  47.        1.  Disable Interrupts.
  48.        2.  Write the CMOS RAM offset which is to be written to port 70h.
  49.        3.  Create a delay.
  50.        4.  Write the data  byte to port 71h.
  51.  
  52.   Note that step 3. may not be necessary on some older machines.  Below
  53.   is a function which given two offsets for a low and high order byte
  54.   will return the word value stored in the CMOS.  This can be easily
  55.   modified to write a word to the CMOS RAM.
  56.   \* -------------------[  ACCESSING CMOS DATA ]------------------------ */
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                                    NUMBER  :  1157
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  November 11, 1992                                 PAGE  :  2/3
  78.  
  79.     TITLE  :  Determining Extended Memory Size from CMOS.
  80.  
  81.  
  82.  
  83.  
  84.   /* ----------------------------------------------------------------- *\
  85.   |                                                                     |
  86.   |   This function will fetch a word from the cmos given the low byte  |
  87.   |   offset and high byte offset in the cmos.                          |
  88.   |                                                                     |
  89.   \* ----------------------------------------------------------------- */
  90.  
  91.   #include <dos.h>
  92.   #include <stdio.h>
  93.   #pragma inline
  94.  
  95.   const int CMOS_PORT_WRITE = 0x70;
  96.   const int CMOS_PORT_READ  = 0x71;
  97.  
  98.   unsigned get_cmos( unsigned char low, unsigned char high );
  99.  
  100.  
  101.   int main()
  102.   {
  103.        unsigned ext;                /* Extended memory in Kilobytes      */
  104.        ext = get_cmos( 0x30, 0x31 );/* Get extended detected during POST */
  105.        printf( "Installed extended memory detected by POST:  %8uk\n", ext );
  106.        return( 0 );
  107.   }
  108.  
  109.  
  110.   unsigned get_cmos( unsigned char low, unsigned char high )
  111.   {
  112.        unsigned word;
  113.        unsigned char *p;
  114.        unsigned char  l,h;
  115.  
  116.        p = ( unsigned char *) &word;
  117.  
  118.        disable();
  119.  
  120.        outportb( CMOS_PORT_WRITE, high );
  121.        asm jmp short $+2
  122.        h = inportb( CMOS_PORT_READ );
  123.  
  124.        outportb( CMOS_PORT_WRITE, low );
  125.        asm jmp short $+2
  126.        l = inportb( CMOS_PORT_READ );
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                                    NUMBER  :  1157
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  November 11, 1992                                 PAGE  :  3/3
  144.  
  145.     TITLE  :  Determining Extended Memory Size from CMOS.
  146.  
  147.  
  148.  
  149.  
  150.        *p = l;
  151.        *(p+1) = h;
  152.  
  153.        enable();
  154.        return word;
  155.   }
  156.  
  157.  
  158.  
  159.   DISCLAIMER: You have the right to use this technical information subject
  160.   to the terms of the No-Nonsense License Statement that you received with
  161.   the Borland product to which this information pertains.
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.